<&contentdata 
section_name = 'tools'
page_name = 'sky_password'
author = 'mrmt32'
type = 'page'
>
<div class="settingsPage">
	<h2>Sky Defaults Calculator</h2>
	
	<p>Using this page you can calculate the Sky username and password, the default wireless password, the default wireless channel and the default wireless SSID from your router's LAN MAC address.</p>
	<form id="skyDefaultsForm">
		<$$loading_text_block:{}>
	</form>
	
	<&javascript delayed='true'>
		SendCommandToServer({action:'get_value', type:'current', name:'lanMacAddress'}, function(jsonResponse)
		{
			if (jsonResponse.isError)
			{
				jsonResponse.ReturnData = {lanMacAddress: ""};
			}

			$("#skyDefaultsForm").submit(function()
			{
				$.post(InterfaceLocation + "?action=calculate_defaults",  $("#skyDefaultsForm").serialize(), function(jsonResponse)
				{
					ParseContentData(window.ContentData.blocks.sky_defaults_results_block, {jsonResponse: jsonResponse}, function (output)
					{
						$(".settingsPage").html(output);
					});
					
				}, "json");
				
				ParseContentData(window.ContentData.blocks.loading_text_block, {}, function (output)
				{
					$(".settingsPage").html(output);
				});
				return false;
			});
			
			ParseContentData(window.ContentData.blocks.sky_defaults_form_block, jsonResponse.ReturnData, function(output)
			{
				$("#skyDefaultsForm").html(output);
			})
		});

	<&/javascript>
</div>
<&/contentdata>

<&contentdata
block_name = 'sky_defaults_form_block'
author = 'mrmt32'
type = 'block'
>
	<fieldset class="wide">
		<p><label for='lanMacAddress'>LAN MAC Address: </label><input name='lanMacAddress' id='lanMacAddress' type='text' value='<$lanMacAddress>' /></p>
		<p id='serialNumberBox'>
			<&javascript delayed='true'>
				$("#routerType").change(function ()
				{
					switch ($("#routerType option:selected").val())
					{
						case "v1":
							$("#serialNumberBox").html("")
							break;
						
						case "v2":
							$("#serialNumberBox").html("<label for='serial'>Serial Number: </label><input name='serial' id='serial' type='text' value='' />");
							break;
							
						case "v3":
							alert("Sky V3 (Black Sagum) not yet supported!");
							break;
					}
				});
			<&/javascript>
		</p>

		<p>
			<label for='routerType'>Router Type: </label>
			<select id='routerType'>
				<option value='v1' selected="selected">Sky V1 - DG834GT (White Netgear)</option>	
				<option value='v2'>Sky V2 - DG934G (Black Netgear)</option>
				<option value='v3'>Sky V3 - (Black Sagum)</option>
			</select>
		</p>
	</fieldset>
	<fieldset class="wide">
		<p class='submitButton'><input type="submit" value="Calculate" /></p>
	</fieldset>
<&/contentdata>

<&contentdata
block_name = 'sky_defaults_results_block'
author = 'mrmt32'
type = 'block'
>
	<h2>Sky Defaults</h2>
	
	<&javascript>
		if (parameters.jsonResponse.isError)
		{
			output = "<p>An error occured getting the values. The error returned was:</p>"
				    + "<p><textarea cols='50' rows='9'>" + parameters.jsonResponse.ErrorString + "</textarea></p>";
		}
		else
		{
			output = "<p>The default values are:</p>";
			output += "<table><tbody>";
			
			for (setting in parameters.jsonResponse.ReturnData)
			{
				output += "<tr>";
				output += "<td>" + setting + "</td>";
				output += "<td>" + parameters.jsonResponse.ReturnData[setting] + "</td>";
				output += "</tr>";
			}
			
			output += "</tbody></table>";
		}
	<&/javascript>
	
	<p><button onclick="ChangePage(document.location.hash.substring(1))">OK</button></p>
<&/contentdata>